function refresh(){
	document.location.href ="/adminconsole/RoomsManager/BillMessages/BillMessages.jsp";
}

///////////////////// EDIT MESSAGE RESERVATION FOLIO /////////////////////

function saveMessageFolio(){
	var txtMessage = CKEDITOR.instances['txtMessage'].getData();
	var thxMessage = CKEDITOR.instances['thxmessage'].getData();
	var pic = $("#pic").val();
	var id = $("#tableform").attr("refid");
	var url = "/messagefolioService";
	if(id == null){
		var func = "addMessageFolio";
	}else{
		var func = "editMessageFolio"
	}
	var data = { func : func,
			id : id,
			txtMessage : txtMessage,
			pic : pic,
			thxMessage : thxMessage
		}
	simpleservice(url,data,EditMessageFolio);
}

function EditMessageFolio(){
	var url = "/messagefolioService";
	var func = "getMessageFolio";
	var data = { func : func
		}
	simpleservice(url,data,SetMessageFolio);
}

function SetMessageFolio(data){
	if(data != "null"){
		var objArray = new Array();
		objArray = JSON.parse(data);
		var checkLogOut = checkSessionAdmin(objArray);
		if(checkLogOut)
			return;
		$("#tableform").attr("refid",objArray['id']);
		CKEDITOR.instances['txtMessage'].setData(objArray['message']);
		CKEDITOR.instances['thxmessage'].setData(objArray['thxmessage']);
		$("#pic").val(objArray['pic']);
	}
}

///////////////////// EDIT MESSAGE CHECK OUT /////////////////////
function saveMessageCheckOut(){
	var txtMessage = CKEDITOR.instances['txtMessageCheckOut'].getData();
	var thxMessage = CKEDITOR.instances['thxmessageCheckOut'].getData();
	var id = $("#tableform").attr("refid");
	
	var url = "/messageCheckOutService";
	
	if(id == null || id == ""){
		var func = "addMessageCheckOut";
	}else{
		var func = "editMessageCheckOut"
	}
	var data = { func : func,
			id : id,
			txtMessage : txtMessage,
			thxMessage : thxMessage
		}
	simpleservice(url,data,refresh);
}

function EditMessageCheckOut(){
	var url = "/messageCheckOutService";
	var func = "getMessageCheckOut"

	var data = { func : func
		}
	simpleservice(url,data,SetMessageCheckOut);
}

function SetMessageCheckOut(data){
	if(data != ""){
		var objArray = new Array();
		objArray = JSON.parse(data);
		$("#tableform").attr("refid",objArray['id']);
		CKEDITOR.instances['txtMessageCheckOut'].setData(objArray['message']);
		CKEDITOR.instances['thxmessageCheckOut'].setData(objArray['thxmessage']);
	}
}

///////////////////// EDIT MESSAGE CHECK IN /////////////////////
function advancechange(){
	if($("#editadvance").is(":checked")){
		$("#showcardbody").css("display","");
	}else{
		$("#showcardbody").css("display","none");
	}
}

function saveMessageCheckIn(){
	var txtMessage = CKEDITOR.instances['txtMessageCheckIn'].getData();
	var thxMessage = CKEDITOR.instances['thxmessageCheckIn'].getData();
	var checkincardbody = CKEDITOR.instances['checkincardbody'].getData();
	var ispublish = $("#ispublish").is(":checked");
	var id = $("#tableform").attr("refid");
	
	var url = "/messageCheckInService";
	
	if(id == null || id == ""){
		var func = "addMessageCheckIn";
	}else{
		var func = "editMessageCheckIn"
	}
	var data = { func : func,
			id : id,
			txtMessage : txtMessage,
			thxMessage : thxMessage,
			cardbody : checkincardbody,
			ispublish : ispublish
		}
	simpleservice(url,data,refresh);
}

function EditMessageCheckIn(){
	var url = "/messageCheckInService";
	var func = "getMessageCheckIn"

	var data = { func : func
		}
	simpleservice(url,data,SetMessageCheckIn);
}

function SetMessageCheckIn(data){
	if(data != ""){
		var objArray = new Array();
		objArray = JSON.parse(data);
		$("#tableform").attr("refid",objArray['id']);
		CKEDITOR.instances['txtMessageCheckIn'].setData(objArray['message']);
		CKEDITOR.instances['thxmessageCheckIn'].setData(objArray['thxmessage']);
		CKEDITOR.instances['checkincardbody'].setData(objArray['cardbody']);
		$("#ispublish").attr('checked',objArray['publishonweb']);
	}
}
